﻿namespace LeekGPTApp.Library.Services;

public class EvaluateService : IEvaluateService {
    private const int POSITIVE_WEIGHT = 2;
    private const double NEUTRAL_WEIGHT = 0.5;
    private const int NEGATIVE_WEIGHT = -2;

    public double Evaluate(string keys) {
        string[] keylist = keys.Split('\n');
        string[] Positivekeys = keylist[0].Split(':')[1].Split('，');
        string[] Negativekeys = keylist[1].Split(':')[1].Split('，');
        string[] Neutralkeys = keylist[2].Split(':')[1].Split('，');

        int countPos;
        if (Positivekeys.Length == 1) 
            countPos = Positivekeys[0] == "" || Positivekeys[0] == "\r" ? 0 : 1;
        else 
            countPos = Positivekeys.Length;
        
        int countNeg;
        if (Negativekeys.Length == 1)
            countNeg = Negativekeys[0] == "" || Negativekeys[0] == "\r" ? 0 : 1;
        else
            countNeg = Negativekeys.Length;

        int countNeu;
        if (Neutralkeys.Length == 1)
            countNeu = Neutralkeys[0] == "" || Neutralkeys[0] == "\r" ? 0 : 1;
        else
            countNeu = Neutralkeys.Length;




        double sum = countPos * POSITIVE_WEIGHT +
            countNeg * NEGATIVE_WEIGHT +
            countNeu * NEUTRAL_WEIGHT;

        string state = string.Empty;
        if (sum >= 10)
            state = "非常健康";
        else if (sum >= 5)
            state = "健康";
        else if (sum >= 1)
            state = "基本健康";
        else if (sum == 0)
            state = "中立";
        else if (sum >= -5)
            state = "基本不健康";
        else if (sum >= -10)
            state = "不健康";
        else
            state = "非常不健康";

        string percent;
        if (Positivekeys.Length > Negativekeys.Length)
            percent = "积极描述占比较多";
        else if (Positivekeys.Length == Negativekeys.Length 
                 && Positivekeys.Length != 0 && Negativekeys.Length != 0)
            percent = "描述好坏参半";
        else if (Negativekeys.Length != 0)
            percent = "消极描述占比较多";
        else 
            percent = "描述多为中立";

        return sum;
    }
}

